version 14.2
set more off
set matsize 11000

***********************************************************************************************************************
* THIS ROUTINE GENERATES TABLE III OF WASEEM (2020) ROLE OF WITHHOLDING ...
***********************************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* ALL FIRMS */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
keep					if fy>1996 & fy<=2010
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=1999)
g						treat_after=treat*after						
g						lnsales=log(domsale_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=1997/2009 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* POPULATING THE TABLE */

qui						areg lnsales pdum2-pdum36 treat treat_after if fy<=1999, absorb(regnor) cluster(ind)
matrix					table[1,1]=_b[treat_after]
matrix					table[2,1]=_se[treat_after]
matrix					table[15,1]=e(N)
local					j=2
local					q=2
local					k=48
forvalues				y=2000/2005 {
local					i=1
qui						areg lnsales pdum2-pdum`k' treat treat_after treat_`y' if fy<=`y', absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
local					i=`i'+`q'
matrix					table[`i',`j']=_b[treat_`y']
matrix					table[`i'+1,`j']=_se[treat_`y']
matrix					table[15,`j']=e(N)
local					j=`j'+1
local					q=`q'+2
local					k=`k'+12
}

/* FORMATTING TABLE */ 

svmat 			table
keep			tab*
drop			table8-table12
keep			if _n<=15
g				c15=""
replace			c15="$\mbox{\emph{Manuf}} \times \mbox{\emph{Post}}$" in 1
replace			c15="$\mbox{\emph{Manuf}} \times \mbox{\emph{2000}}$" in 3
replace			c15="$\mbox{\emph{Manuf}} \times \mbox{\emph{2001}}$" in 5
replace			c15="$\mbox{\emph{Manuf}} \times \mbox{\emph{2002}}$" in 7
replace			c15="$\mbox{\emph{Manuf}} \times \mbox{\emph{2003}}$" in 9
replace			c15="$\mbox{\emph{Manuf}} \times \mbox{\emph{2004}}$" in 11
replace			c15="$\mbox{\emph{Manuf}} \times \mbox{\emph{2005}}$" in 13
replace			c15="Observations" in 15
forvalues 		c=1/7 {
g				c`c'=string(table`c',"%9.3f")
}
local			r=2
forvalues		c=1/7 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
local			r=`r'+2
}
forvalues		c=1/7 {
replace			c`c'=string(table`c',"%15.0fc") in 15
}
forvalues		c=1/7 {
replace			c`c'="" if c`c'=="0.000"
}
forvalues		s=1/15 {
g				s`s'="&"
}
g				l="\\"
forvalues		r=2(2)14 {
replace			l="\\\\" in `r'
}
order			c15 s15 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 l
browse			c15 s15 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 l

